package cn.ultrarisk.scadmin.manager.web.controller.collection;

import cn.ultrarisk.scadmin.manager.biz.solr.dao.SolrCollectionDAO;
import cn.ultrarisk.scadmin.manager.biz.solr.dao.SolrReplicaDAO;
import cn.ultrarisk.scadmin.manager.biz.solr.dto.CollectionOverview;
import cn.ultrarisk.scadmin.manager.biz.solr.dto.ReplicaOverview;
import cn.ultrarisk.scadmin.manager.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * OverviewController
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/4/17
 * @since V1.0
 */
@Controller
@RequestMapping(value = "/collection/{id}/overview")
public class OverviewController extends BaseController {
    @Autowired
    private SolrCollectionDAO solrCollectionDAO;
    @Autowired
    private SolrReplicaDAO solrReplicaDAO;

    @ResponseBody
    @RequestMapping(value = "")
    public ResponseEntity<Map<String, Object>> overview(@PathVariable("id") Integer id) {
        Map<String, Object> map = new HashMap<String, Object>();

        CollectionOverview collectionOverview = solrReplicaDAO.getCollectionOverview(id);
        List<ReplicaOverview> replicaOverviews = solrReplicaDAO.getReplicaOverviews(id);

        map.put("collection", collectionOverview);
        map.put("replicas", replicaOverviews);
        return getOkResponseEntity(map);
    }
}
